$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/withdraw/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '申请人姓名', name: 'applyname', index: 'applyname', width: 80 },
			{ label: '申请者电话', name: 'applyphone', index: 'applyphone', width: 80 }, 			
			{ label: '提现金额(元)', name: 'money', index: 'money', width: 80, formatter: function(value, options, row){
                return value / 100 }   },
			{ label: '提现后剩余蝉币', name: 'balance', index: 'balance', width: 80, formatter: function(value, options, row){
                return value / 100 }   },
			{ label: '申请状态', name: 'status', index: 'status', width: 80,formatter: function(value, options, row){
                if(value === 0){
                    return '<span class="label label-primary">已申请</span>';
                }
                if(value === 1){
                    return '<span class="label label-success">已通过</span>';
                }
                if(value === 2){
                    return '<span class="label label-warning">已拒绝</span>';
                }
                if(value === 3){
                    return '<span class="label label-info">已打款</span>';
                }
            }  },
			{ label: '创建时间', name: 'createdate', index: 'createdate', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
        showList2: true,
		title: null,
		withdraw: {},
        q:{
            applyphone:null
        },
        sels: [
            {value:"0",week:"已申请"},
            {value:"1",week:"已通过"},
            {value:"2",week:"已拒绝"},
            {value:"3",week:"已打款"}
        ],
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.withdraw = {};
		},
		check: function(){
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.title = "审核";

            vm.getInfo(id)
        },
        remittance: function(){
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList2 = false;
            vm.title = "汇款";

            vm.getInfo(id)
        },
        pass:function () {
            $.ajax({
                type: "POST",
                url: baseURL + "sys/withdraw/pass",
                contentType: "application/json",
                data: JSON.stringify(vm.withdraw),
                success: function(r){
                    if(r.code === 0){
                        alert('审核成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        refuse:function () {
            $.ajax({
                type: "POST",
                url: baseURL + "sys/withdraw/refuse",
                contentType: "application/json",
                data: JSON.stringify(vm.withdraw),
                success: function(r){
                    if(r.code === 0){
                        alert('审核成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        remit:function () {
            $.ajax({
                type: "POST",
                url: baseURL + "sys/withdraw/remit",
                contentType: "application/json",
                data: JSON.stringify(vm.withdraw),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.withdraw.id == null ? "sys/withdraw/save" : "sys/withdraw/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.withdraw),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "withdraw/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/withdraw/info/"+id, function(r){
                vm.withdraw = r.withdraw;
            });
		},
        cateName: function () {
            vm.showList = true;
            vm.showDom = 'list'
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'status': this.withdraw.status
                },
                page: page
            }).trigger("reloadGrid");
        },
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{'applyphone': vm.q.applyphone},
            }).trigger("reloadGrid");
		}
	}
});